package com.nega.commons.config;

import com.nega.commons.spider.IPSourcePool;
import com.nega.commons.spider.core.IPSourceMoreTime;
import com.nega.modules.Task.ScheduledClearSearchResult;
import com.nega.modules.handler.SearchCenterServiceImpl;
import com.nega.modules.handler.Spider360ServiceImpl;
import com.nega.modules.handler.SpiderBaiduServiceImpl;
import com.nega.modules.handler.SpiderSouGouServiceImpl;
import com.nega.modules.handler.SpiderWeiBoServiceImpl;
import com.nega.modules.service.SearchCenterService;
import com.nega.modules.service.SpiderService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Garcia
 * @CreateDate: 2019/5/10 0:11
 * @Description: what it is class?
 */
@Configuration
public class ServiceConfiguration {

    @Resource
    private SpiderBaiduServiceImpl spiderBaiduService;

    @Resource
    private SpiderSouGouServiceImpl spiderSouGouService;

    @Resource
    private Spider360ServiceImpl spider360Service;

    @Resource
    private SpiderWeiBoServiceImpl spiderWeiBoService;

    @Bean
    public SearchCenterService searchCenterService(){
        List<SpiderService> spiderServices = new ArrayList<>();
        spiderServices.add(spiderBaiduService);
        spiderServices.add(spiderSouGouService);
        spiderServices.add(spider360Service);
        spiderServices.add(spiderWeiBoService);
        SearchCenterServiceImpl searchCenterService = new SearchCenterServiceImpl();
        searchCenterService.setSpiderServices(spiderServices);
        return  searchCenterService;
    }

    @Bean
    public JavaMailSenderImpl javaMailSenderImpl(){
        return new JavaMailSenderImpl();
    }

    /***
     * 使用复用IP池
     * @return
     */
    @Bean
    public IPSourcePool ipSourcePool(){
        return new IPSourceMoreTime();
    }
}
